package com.hzj.controller;

import com.hzj.pojo.BolgComment;
import com.hzj.pojo.BolgDatail;
import com.hzj.service.BokeService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class BokeController {
    @Autowired
//    @Qualifier("bokeService")
    BokeService bs;

    @RequestMapping("/testcom")
    @HystrixCommand(fallbackMethod = "testHystrix")
    public String testcom(HttpServletRequest request) {
        String token = request.getHeader("token");
        System.err.println(token);
        return bs.test();
    }

    @RequestMapping("/loginZull")
    public String login(@RequestParam String username, @RequestParam String password) {
        return bs.login(username, password);
    }

    //    @RequestMapping("")
    @RequestMapping("/showAll")
    public List<BolgDatail> showAll() {
        return bs.showAll();
    }

    @PostMapping("/add")
    public String add(BolgComment bolgComment) {
        System.out.println(bolgComment);
        return bs.add(bolgComment);
    }


    public String testHystrix(HttpServletRequest request) {
        return "我是熔断";
    }


    @RequestMapping("/session")
    public Object session(HttpSession session) {
        bs.session();
        System.out.println("user==>" + session.getAttribute("user") + "    id:" + session.getId());
        return session.getAttribute("user");
    }

    @RequestMapping("/session1")
    public String session1(HttpSession session) {
        session.setAttribute("user", "baba");
        System.out.println("9002-id:" + session.getId() + "|值：" + session.getAttribute("user"));
        String s = bs.session1();
        System.out.println("消费者值:" + s);
        return s;
    }
}
